import { Controller, Post, Get, Req, Res } from "routing-controllers";
import { GOODS_INTERFACE, goodsInterface } from "service/goods/goods";
import { Inject, Service } from "typedi";
import { SitesList, SitesOptions } from "client/sitesVo";
import { VALID_TOKEN } from "config/const";

@Controller()
@Service()
export class GoodsController {
  @Inject(GOODS_INTERFACE) private readonly goods: goodsInterface;

  // {listParams:列表参数,totalParams:上架状态统计个数参数}
  @Post("/goods/list")
  async list(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesList[] | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.goods.getList({ request, response, userInfo });
  }

  // 没有参数
  @Post("/goods/options")
  async options(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesList[] | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.goods.getOptions({ request, response, userInfo });
  }

  // 不动
  @Post("/goods/hidden")
  async hidden(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesList[] | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.goods.hidden({ request, response, userInfo });
  }

  // 不动
  @Post("/goods/delete")
  async delete(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesList[] | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.goods.delete({ request, response, userInfo });
  }

  // 获取sku信息
  @Get("/goods/get_sku")
  async get_sku(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesList[] | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.goods.get_sku({ request, response, userInfo });
  }

  // 批量更新产品是否在白名单
  @Post("/goods/update_white")
  async update_white(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesList[] | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.goods.update_white({ request, response, userInfo });
  }

  // 查询商品详情
  @Post("/product/get_detail")
  async get_detail(
    @Req() request: any,
    @Res() response: any
  ): Promise<SitesList[] | any> {
    const userInfo = await VALID_TOKEN({ request, response });
    return this.goods.get_detail({ request, response, userInfo });
  }
}
